/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sms4j.config;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *
 * @author Swang
 */
public class Config {

    private static final Log log = LogFactory.getLog(Config.class);
    public static int SOCKET_MESSAGE_LISTENER_PORT = 5001;
    public static String SOCKET_CLIENT_ALLOW_IP_PATTERN = "192.168.1.*;localhost;127.0.0.1";
    public static String SOCKET_INPUTSTREAM_ENCODE = "gbk";
    public static String GSM_MODEM_GATEWAY_ID = "gsmmodem.com1";
    public static String GSM_MODEM_GATEWAY_COM_PROT = "COM1";
    public static int GSM_MODEM_GATEWAY_BAUD_RATE = 9600;
    public static String GSM_MODEM_GATEWAY_MANUFACTURER = "WAVECOM";
    public static String GSM_MODEM_GATEWAY_MODEL = "1800";

    public static void init() {
        try {
            Configuration config = new PropertiesConfiguration("sms4j.properties");
            SOCKET_MESSAGE_LISTENER_PORT = config.getInt("SOCKET_MESSAGE_LISTENER_PORT", SOCKET_MESSAGE_LISTENER_PORT);
            SOCKET_CLIENT_ALLOW_IP_PATTERN = config.getString("SOCKET_CLIENT_ALLOW_IP_PATTERN", SOCKET_CLIENT_ALLOW_IP_PATTERN);
            SOCKET_INPUTSTREAM_ENCODE = config.getString("SOCKET_INPUTSTREAM_ENCODE", SOCKET_INPUTSTREAM_ENCODE);
            GSM_MODEM_GATEWAY_ID = config.getString("GSM_MODEM_GATEWAY_ID", GSM_MODEM_GATEWAY_ID);
            GSM_MODEM_GATEWAY_COM_PROT = config.getString("GSM_MODEM_GATEWAY_COM_PROT", GSM_MODEM_GATEWAY_COM_PROT);
            GSM_MODEM_GATEWAY_MANUFACTURER = config.getString("GSM_MODEM_GATEWAY_MANUFACTURER", GSM_MODEM_GATEWAY_MANUFACTURER);
            GSM_MODEM_GATEWAY_MODEL = config.getString("GSM_MODEM_GATEWAY_MODEL", GSM_MODEM_GATEWAY_MODEL);
            GSM_MODEM_GATEWAY_BAUD_RATE = config.getInt("GSM_MODEM_GATEWAY_BAUD_RATE", GSM_MODEM_GATEWAY_BAUD_RATE);
            log.info("SOCKET_MESSAGE_LISTENER_PORT:" + SOCKET_MESSAGE_LISTENER_PORT);
            log.info("SOCKET_CLIENT_ALLOW_IP_PATTERN:" + SOCKET_CLIENT_ALLOW_IP_PATTERN);
            log.info("SOCKET_INPUTSTREAM_ENCODE:" + SOCKET_INPUTSTREAM_ENCODE);
            log.info("GSM_MODEM_GATEWAY_ID:" + GSM_MODEM_GATEWAY_ID);
            log.info("GSM_MODEM_GATEWAY_COM_PROT:" + GSM_MODEM_GATEWAY_COM_PROT);
            log.info("GSM_MODEM_GATEWAY_MANUFACTURER:" + GSM_MODEM_GATEWAY_MANUFACTURER);
            log.info("GSM_MODEM_GATEWAY_MODEL:" + GSM_MODEM_GATEWAY_MODEL);
            log.info("GSM_MODEM_GATEWAY_BAUD_RATE:" + GSM_MODEM_GATEWAY_BAUD_RATE);
        } catch (ConfigurationException ex) {
            Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex);
        }


    }
}
